Object = BaseClass:Extend()

function Object:New(o)
    local o = Object.super.New(self)
    --o:Init()
    return o
end

function Object:Load(mod_name,load_func)
    local ab_name = "model_"..mod_name.."_mod"
    ResManager:GetInstance():LoadRes(self,ab_name,mod_name,nil, function(obj)
        self.obj = GameObject.Instantiate(obj)
        self:BeforeLoadSuccess(self.obj)
        self:InitEvent()
        self:LoadSuccess()
        if load_func then
            load_func(self.obj)
        end
    end)
end

function Object:BeforeLoadSuccess()
    self:SetParent()
end

function Object:LoadSuccess()
    --子类用
end


function Object:InitEvent()
    --子类用
end

function Object:SetParent(parent)
    print(SceneController.root,self.obj)
    self.obj.transform.parent = parent or SceneController.root
end

function Object:__delete()
    ResManager:GetInstance():ClearAllRef(self)
    if self.pool then
        PoolManager:GetInstance():SetObject("PoolObj",self)
    else
        GameObject.DestroyImmediate(self.obj,true)
    end
    --解绑事件
    if self.event_list and next(self.event_list) then
        for i, v in pairs(self.event_list) do
            v.dispatcher:UnBind(i)
        end
    end
    self.event_list = nil
end

function Object:BindEvent (dispatcher,event_id,func)
    local id = dispatcher:Bind(event_id,func)
    self.event_list = self.event_list or {}
    self.event_list[id] = {dispatcher = dispatcher}
end

function Object_Init(mod_name,load_func,class)
    local class = class or Object
    local obj = class:New()
    obj:Load(mod_name,load_func)
    return obj
end